<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.lms.pojo.Book" %>
<%@ page import="java.util.*" %>
<%@ page import="com.github.pagehelper.PageInfo" %>
<%@ page import="com.lms.utils.GetCategoryUtil" %>
<%@ page import="com.lms.pojo.Category" %><%--
  Created by IntelliJ IDEA.
  User: hsy
  Date: 2023/5/24
  Time: 10:43
  To change this template use File | Settings | File Templates.
--%>
<html>
<head>
    <title>查看所有图书</title>
    <link rel="stylesheet" type="text/css" href="css/showAllBook.css">
</head>
<body>
<div class="container">
    <%--共同侧边栏--%>
    <%@ include file="sidebar.jsp" %>
    <div class="contain">
        <table class="nav" border="0">
        </table>
    </div>
    <form method="get" action="searchBookServlet">
        <tr>
            <td>图书编号</td>
            <td><input type="number" name="bookID"></td>
        </tr>
        <tr>
            <td>图书名称</td>
            <td><input type="text" name="title"></td>
        </tr>
        <tr>
            <td>作者</td>
            <td><input type="text" name="author"></td>
        </tr>
        <tr>
            <td>出版社</td>
            <td><input type="text" name="publisher"></td>
        </tr>
        <tr>
            <td>图书类型</td>
            <td><select name="categoryID">
                <option value="0">全选</option>
                    <%
                     //调用工具类的方法，查所有的category返回到list集合中
                     List<Category> categoryList = GetCategoryUtil.getCategoryList();%>
                <%--    动态展示图书类型--%>
                    <%
                      for(Category c : categoryList){
                                      %>
                <%--      <option value="1">小说</option>--%>
                <option value="<%=c.getCategoryId()%>"><%=c.getCategoryName()%>
                </option>
                    <%}%>
            </td>
        </tr>
        <tr>
            <td>库存查询</td>
            <td><input type="number" name="min">---<input type="number" name="max"></td>
        </tr>
        <tr>
            <td></td>
            <td>
                <button type="submit">搜索</button>
            </td>

        </tr>


    </form>
    <table class="center" border="1" cellpadding="5" cellspacing="0">


        <h1><a href="bookAdd.jsp">添加新书</a></h1>
        <tr>
            <th>图书编号</th>
            <th>图书名称</th>
            <th>作者</th>
            <th>出版社</th>
            <th>图书类型</th>
            <th>库存</th>
            <th>操作</th>
        </tr>
        <%
            //pageInfo封装了很多信息
            PageInfo<Book> pageInfo = (PageInfo<Book>) request.getAttribute("pageInfo");
            for (Book book : pageInfo.getList()) {
        %>
        <tr>
            <td><%=book.getBookID()%>
            </td>
            <td><%=book.getTitle()%>
            </td>
            <td><%=book.getAuthor()%>
            </td>
            <td><%=book.getPublisher()%>
            </td>
            <td><%=book.getCategoryName()%>
            </td>
            <td><%=book.getStockQuantity()%>
            </td>
            <td>
                <a href="<%=request.getContextPath()%>/BookDeleteServlet?bookId=<%=book.getBookID()%>" onclick="return confirm('确定要删除吗？')">删除</a>
                <a href="<%=request.getContextPath()%>/bookModify.jsp?bookId=<%=book.getBookID()%>&title=<%=book.getTitle()%>&author=<%=book.getAuthor()%>&publisher=<%=book.getPublisher()%>&categoryName=<%=book.getCategoryName()%>&stockQuantity=<%=book.getStockQuantity()%>">修改</a>
            </td>
        </tr>
        <%}%>
    </table>
    <%
        if (pageInfo.getList() == null || pageInfo.getList().size() == 0 || pageInfo.getList().equals("")) {
    %>
    <h3>未找到数据</h3>
    <%}%>
    <%
        Object searchPage = request.getAttribute("searchPage");
        if (searchPage == null) {
    %>
    <a href="<%=request.getContextPath()%>/BookServlet?page=1">首页</a>
    <%}%>
    <%-- 检查上一页 --%>
    <% if (pageInfo.getPrePage() > 0) { %>
    <a href="<%=request.getContextPath()%>/BookServlet?page=<%=pageInfo.getPrePage()%>">上一页</a>
    <% }%>
    <%-- 检查下一页--%>
    <% if (pageInfo.getNextPage() > 0) { %>
    <a href="<%=request.getContextPath()%>/BookServlet?page=<%=pageInfo.getNextPage()%>">下一页</a>
    <% } %>
    <%
        if (searchPage == null) {
    %>
    <a href="<%=request.getContextPath()%>/BookServlet?<%="page=" + pageInfo.getPages()%>">尾页</a>
    <%}%>
    总记录:<%=pageInfo.getTotal()%>条
    当前第 <%=pageInfo.getPageNum()%>页
</div>
</body>
</html>
